package oceanlife.pathfinding;

import java.util.ArrayList;
import java.util.Arrays;

@SuppressWarnings("serial")
public class TriangleArrayList<S> extends ArrayList<S> {

    //@Override
    //public boolean equals (Object other) {
    //}
    
    public int getIndex (Object other){
	    if (!(other instanceof Triangle)) return -1;
        Triangle t = (Triangle) other;
	    for(int k = 0; k < this.size();k++){
	    	S objectFA = this.get(k);
	    	if(objectFA instanceof Triangle){
	    		Triangle triangleFA = (Triangle) objectFA; 
		        if (triangleFA.size() != t.size()) break;
		        boolean[] used = new boolean[triangleFA.size()];
		        Pnt[] triangleFAPnts = triangleFA.toArray(new Pnt[0]);
		        for (Pnt pnt : t){
		        	boolean pntFound = false;
		        	for(int i = 0; i < t.size();i++){
		        		if(!used[i] && pnt.equals(triangleFAPnts[i])){
		        			pntFound = true;
		        			used[i] = true;
		        			break;
		        		}
		        	}
		        	if(!pntFound){
		        		break;
		        	}
		        }
		        boolean triangleFound = true;
		        for(int i = 0; i < used.length;i++){
		        	if(!used[i]){
			        	triangleFound = false;
			        	break;
		        	}
		        }
		        if(triangleFound){
		        	return k;
		        }
	    	}
	    }
        return -1;
    }
}
